<?php slot('contact') ?>
<div class="pealkiri">
	<h1><?php echo $node['pageTitle'] ?></h1>
</div>
<div class="tagasisidebox">

	<form id="contact_form" method="post" action="<?php echo LinkGen::getInstance(LinkGen::RAW_ACTION)->link(null, array('module' => 'contact', 'action' => 'submit')) ?>">
		<?php echo $form->renderHiddenFields(true) ?>
			<?php echo $form['nimi']->render(array('class' => 'sideinput', 'title' => $form->getDefault('nimi')))?>

			<?php echo $form['email']->render(array('class' => 'sideinput','title' => $form->getDefault('email')))?>
			<?php echo $form['lisainfo']->render(array('class' => 'areatext', 'title' => $form->getDefault('lisainfo')))?>
			<?php echo $form['captcha']->render(array('id'=>'contact_captcha', 'class' => 'codein', 'title' => $form->getDefault('captcha')))?>
			<img id="contact_captcha_img" src="/captcha?t=<?php echo time()?>" width="94" height="23" alt=""/><br />
			<div class="sabuttoncenter"><p><a id="contactSubmit" href="#"><?php echo __('saada') ?></a></div>

	</form>
		<div class="clear"></div>
</div>

<script type="text/javascript">
  $('#contactSubmit').click(function(e) {
	e.preventDefault();
	var button = $(this);

	if(button.attr('loading')=='1')return false;

	button.html('<?php echo __('wait') ?>');
	button.attr('loading', 1);
	
	var form = $(this).parents('form');
	var action = form.attr('action');

	$.post(action, form.serialize(), function(data) {
	  if(data.code == 500){ // fail
		  var errs = "";
		  for(var err in data.errors){
			  errs += data.errors[err] + "<br />";
		  }
		  $('#contact_errors').html(errs);
		  
		  // reload captcha
		  var img = $('#contact_captcha_img');
		  img.attr('src', img.attr('src') + '1');

		  button.attr('loading', 0);
		  button.html('<?php echo __('saada') ?>');
	  }else{ // suxass
		form.html(data.notice);
	  }

	},'json');

    return false;
  });
</script>
<?php end_slot() ?>